package com.game.jumper.lghelp;

import java.util.Random;

import org.loon.framework.android.game.core.graphics.LColor;
import org.loon.framework.android.game.core.graphics.LImage;
import org.loon.framework.android.game.core.graphics.device.LGraphics;

import android.R.integer;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;

import com.game.jumper.activity.PlayLG;
import com.game.jumper.bean.Ball;
import com.game.jumper.game.Game;

public class Lg_Ball implements ILgHelp
{

	private Game game;

	private LImage bottom1;

	private LImage bottom2;

	private int circle = 0;

	private LImage balLImage;
	
	public Lg_Ball(Game game)
	{
		// TODO Auto-generated constructor stub
		this.game = game;

		bottom1 = LImage.createImage("assets/bottom1.png");
		bottom2 = LImage.createImage("assets/bottom2.png");
		balLImage=LImage.createImage("assets/ball.png");
	}

	@Override
	public void draw(LGraphics g)
	{
		// TODO Auto-generated method stub
		Ball ball = game.getBall();

		drawball(g,balLImage, (int) ball.getX(), (int) ball.getY(), (int) ball.getR());

		if (circle <= 10)
		{
			g.drawImage(bottom1, 0, g.getClipHeight() - 10, g.getClipWidth(), 10);
		}
		else
		{
			g.drawImage(bottom2, 0, g.getClipHeight() - 10, g.getClipWidth(), 10);
		}
		circle++;
		if (circle >= 20)
		{
			circle = 0;
		}
	}

	void drawball(LGraphics g,LImage img, int x, int y, int r)
	{
		int x1 = x - r;
		int y1 = y - r;
		//g.fillOval(x1, y1, r * 2, r * 2);
		//g.drawImage(img, x1, y1,r * 2, r * 2);
		//g.drawImage(img, x, y, w, h)
		Bitmap image = PlayLG.ballBitmap;
		g.drawBitmap(image, new Rect(0, 0, image.getWidth(), image.getHeight()),
				new Rect(x1, y1, x+r, y+r));
	}

}
